package com.lg.erp.controller.zhangchaofu;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lg.erp.entity.JsonResult;
import com.lg.erp.entity.zhangchaofu.TMoveWarehouse;
import com.lg.erp.entity.zhangchaofu.TIomWarehouse;
import com.lg.erp.entity.zhangchaofu.ZCFTWare;
import com.lg.erp.service.zhangchaofu.MoveWarehouseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class MoveWarehouseController {

    @Autowired
    private MoveWarehouseService moveWarehouseService;

    /**
     * 查询仓库移库的数据
     * @param current
     * @return
     */
    @GetMapping("/moveWarehouse/{current}")
    public JsonResult findMoveWarehousePage(@PathVariable Integer current){
        Page<TMoveWarehouse> page=new Page<>(current,10);
        IPage<TMoveWarehouse> pages =moveWarehouseService.findMoveWarehousePage(page);
        return new JsonResult(1,"ok",pages);
    }

    /**
     * 移出仓库详细信息
     * @param tMoveWarehouse
     * @return
     */
    @ResponseBody
    @PostMapping("/outWarehouse")
    public JsonResult outWarehouseDetails(@RequestBody TMoveWarehouse tMoveWarehouse){
        tMoveWarehouse.setMvIn(null);
        List<TMoveWarehouse> moveWarehouseList = moveWarehouseService.warehouseDetails(tMoveWarehouse);
        return new JsonResult(1,"ok",moveWarehouseList);
    }

    /**
     * 移入仓库详细信息
     * @param tMoveWarehouse
     * @return
     */
    @ResponseBody
    @PostMapping("/inWarehouse")
    public JsonResult inWarehouseDetails(@RequestBody TMoveWarehouse tMoveWarehouse){
        tMoveWarehouse.setMvOut(null);
        List<TMoveWarehouse> moveWarehouseList = moveWarehouseService.warehouseDetails(tMoveWarehouse);
        return new JsonResult(1,"ok",moveWarehouseList);
    }

    /**
     * 查询所有的仓库
     * @return
     */
    @ResponseBody
    @GetMapping("/moveWarehouse-ware")
    public JsonResult findAllWare(){
        List<ZCFTWare> ware =moveWarehouseService.findAllWare();
       return new JsonResult(1,"ok",ware);
    }

    /**
     * 查询货位表上的商品
     * @return
     */
    @ResponseBody
    @GetMapping("/moveWarehouse-cargo")
    public JsonResult findCargo(){
        TMoveWarehouse warehouse = new TMoveWarehouse();
        List<TMoveWarehouse> moveWarehouseList=moveWarehouseService.findCargo(warehouse);
        return new JsonResult(1,"ok",moveWarehouseList);
    }
    /**
     * 根据仓库id和商品名称查询货位表上的商品
     * @return
     */
    @ResponseBody
    @GetMapping("/moveWarehouse-cargo-warename-productName/{wareId}/{productName}")
    public JsonResult findCargoWareAndProductName(@PathVariable("wareId") String wareId,@PathVariable("productName") String productName){
        TMoveWarehouse warehouse = new TMoveWarehouse();
        //判断是否有值
        if (wareId.equals("null")){
            warehouse.setProductName(productName);
        }
        if (productName.equals("null")){
            warehouse.setWareId(wareId);
        }
        if (!wareId.equals("null")&&!productName.equals("null")){
            warehouse.setWareId(wareId);
            warehouse.setProductName(productName);
        }
        List<TMoveWarehouse> moveWarehouseList=moveWarehouseService.findCargo(warehouse);
        return new JsonResult(1,"ok",moveWarehouseList);
    }

    /**
     * 根据仓库id获得对应的货区、货架和货位
     * @return
     */
    @GetMapping("moveWarehouse-ware-cargoArea-shelve-cargo/{wareId}")
    public JsonResult findWareCargoAreaShelveCargo(@PathVariable("wareId") String wareId){
        List<ZCFTWare> wareList=moveWarehouseService.findWareCargoAreaShelveCargo(wareId);
        return new JsonResult(1,"ok",wareList);
    }

    /**
     * 新增出库信息
     * @return
     */
    @ResponseBody
    @PutMapping("iomWarehouse-outWare")
    public JsonResult addIomWarehouseOutWare(@RequestBody TIomWarehouse iomWarehouse){
        TIomWarehouse wareList=moveWarehouseService.addIomWarehouseOutWare(iomWarehouse);
        return new JsonResult(1,"ok",wareList);
    }

    /**
     * 新增入库信息
     * @return
     */
    @ResponseBody
    @PutMapping("iomWarehouse-inWare")
    public JsonResult addIomWarehouseInWare(@RequestBody TIomWarehouse iomWarehouse){
        TIomWarehouse wareList=moveWarehouseService.addIomWarehouseInWare(iomWarehouse);
        return new JsonResult(1,"ok",wareList);
    }

    /*
    * 新增移库信息
    * */
    @ResponseBody
    @PutMapping("moveWarehouse")
    public JsonResult addMoveWarehouse(@RequestBody TMoveWarehouse moveWarehouse){
        moveWarehouseService.addMoveWarehouse(moveWarehouse);
        return new JsonResult(1,"ok",null);
    }
}
